package com.gxc.tree;

import java.util.HashMap;
import java.util.Map;

public class Test {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    public static void main(String[] args) {
        TreeNode test = test(new Integer[]{1, 2, 3, null, 4, 5, null});
        System.out.println("===");
    }

    public static TreeNode test(Integer[] a) {
        TreeNode root = new TreeNode(a[0]);

        Map<Integer, TreeNode> map = new HashMap<>();
        map.put(0, root);
        for (int i = 1; i < a.length; i++) {
            if (a[i] == null) continue;
            TreeNode child = new TreeNode(a[i]);
            map.put(i, child);
            int index = (i-1)/2;
            TreeNode parent = map.get(index);
            if (i % 2 == 0) {
                parent.right = child;
            } else {
                parent.left = child;
            }
        }
        return root;
    }
}
